<template>
  <!-- 灾情信息 - 编辑 -->
  <div class="EmergencyList">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/EDManagement' }">应急处置</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/DisasterReporting' }">灾情信息</el-breadcrumb-item>
        <el-breadcrumb-item>灾情报送任务单</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="box">
      <!-- 列表筛选 -->
      <filterTitle @query="query" @reset="reset" :form="form" :formData="formData" labelWidth="140px"
        @node-click="handleSelectTree" @change="selectChange">
        <!-- <el-form slot="filter" class="form" ref="form" :model="form" inline size="small" label-width="140px">
          <el-form-item :label="item.label + '：'" v-for="(item, index) in formData" :key="index" :rules="rules[item.id]"
            :prop="item.id">
            <LsdForm :compData="item" :form="form" @node-click="handleSelectTree(arguments, item)"
              @change="selectChange(arguments, item)" />
          </el-form-item>
        </el-form> -->
      </filterTitle>
      <!-- 列表表格 -->
      <LsdTable slot="gjxm" :paginationAtrrs="paginationAtrrs" :compRef="table.compRef" ref="gjxm"
        @pageChange="handleSizeChange" :columns="table.columns" :title="table.title" :actions="table.actions"
        :tableData="table.tableData" :tableAttr="table.tableAttr" :isShowPage="table.isShowPage"
        :isSelectFlag="table.isSelectFlag" :isSequenceFlag="table.isSequenceFlag" @onActionClick="onActionClick" />
    </div>
    <!-- 弹窗信息 -->
    <LsdDialog :dialogConfig="dialogConfig" @handleBtn="handleBtn" @close="close">
      <LsdDialogTitle slot="dialog" :titleConfig="titleConfig" :activeNames="activeNames">
        <DialogForm ref="formConfigData" slot="slot1" @changeEvent="handleChange" :formConfig="formConfig1" />
        <div slot="slot2">
          <DialogForm ref="formComponentData" :formConfig="formConfig2" />
          <LsdTable slot="rwxx" :paginationAtrrs="paginationAtrrs" :autoHeight="tableList.autoHeight"
            :compRef="tableList.compRef" ref="gjxm" :columns="tableList.columns" :tableData="tableList.tableData"
            :tableAttr="tableList.tableAttr" :isSequenceFlag="tableList.isSequenceFlag" />
        </div>
        <div slot="slot3">
          <DialogForm ref="formInfoData" :formConfig="formInfoData" />
        </div>
        <!-- <div slot="slot4">
          <DialogForm ref="formCheckData" :formConfig="formCheckData" />
        </div> -->
      </LsdDialogTitle>
    </LsdDialog>
  </div>
</template>

<script>
import { zqbsSubmissionList, getYjsj, getYjsjGetById, zqbsSubmissiongetById, postDeleteData, addAave, zqkcFeedbackUpdById, exportFileApi } from "@/api/EmergencyDisposal/zqbs.js";
// 公共组件接口
import { getDictByGroupEmergency, getDictByGroup, getOrgListTree, GetOrgTreeTwo, GetOrgTreeMore, getOrgDepartmentList } from "@/api/common.js";
import common from "@/utils/common.js";
import { showTime } from "@/lib";
import { flowSubmit } from "@/utils/flow";
export default {
  name: "EmergencyList",
  components: {},
  data() {
    return {
      xinzengNum: 0,
      zrbmOption: [],
      zrdwOption: [], // 报送单位/部门
      fid: "",
      // 筛选信息
      formData: [
        {
          elType: "input",
          id: "emergencyEvent",
          label: "应急事件",
          attrs: {
            value: "",
            size: "small",
            "collapse-tags": true,
            clearable: true
          }
        },
        {
          elType: "select",
          id: "eventCode",
          label: "事件类别",
          dic: "dic_sjlb",
          attrs: {
            value: "",
            size: "small",
            // clearable: true,
            filterable: true,
            "collapse-tags": true,
            clearable: true
          },
          options: []
        },
        {
          elType: "select",
          id: "eventLvName",
          label: "事件级别",
          dic: "dic_sjjb",
          attrs: {
            value: "",
            // clearable: true,
            size: "small",
            filterable: true,
            "collapse-tags": true,
            clearable: true
          },
          options: this.banzuData
        },
        // {
        //   elType: "select",
        //   id: "operatId",
        //   label: "影响范围",
        //   dic: "dic_yxfw",
        //   attrs: {
        //     value: "",
        //     size: "small",
        //     // clearable: true,
        //     filterable: true,
        //     "collapse-tags": true
        //   },
        //   options: this.dishiData
        // },
        // {
        //   elType: "dateTimePicker",
        //   id: "occurrenceTime",
        //   label: "发生时间",
        //   attrs: {
        //     value: "",
        //     size: "small",
        //     type: "datetime",
        //     "value-format": "yyyy-MM-dd HH:mm:ss"
        //   }
        // },
        {
          elType: "dateTimePicker",
          id: "occurrenceTime",
          label: "发生时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            "value-format": "yyyy-MM-dd HH:mm:ss",
            clearable: true
          }
        },

        {
          elType: "input",
          id: "taskName",
          label: "任务名称",
          dic: "dic_xxly",
          attrs: {
            value: "",
            size: "small",
            // clearable: true,
            filterable: true,
            "collapse-tags": true,
            clearable: true
          }
          // options: this.dishiData
        },
        {
          elType: "selectTree",
          id: "operatId",
          name: "operat",
          label: "报送单位/部门",
          attrs: {
            value: "",
            clearable: true,
            "collapse-tags": true
          },
          options: {
            attrs: {
              value: ""
            }
          },
          treeData: {
            attrs: {
              data: []
            },
            props: {
              children: "children",
              label: "orgName",
              value: "id"
            }
          }
        },
        {
          elType: "dateTimePicker",
          id: "issueTime",
          label: "下发时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            "value-format": "yyyy-MM-dd HH:mm:ss",
            clearable: true
          }
        }
        // {
        //   elType: "select",
        //   id: "reportState",
        //   label: "状态",
        //   attrs: {
        //     value: "",
        //     size: "small",
        //     // clearable: true,
        //     filterable: true,
        //     "collapse-tags": true
        //   }
        //   // options: this.dishiData
        // }
      ],
      // 表格信息
      table: {
        isSelectFlag: false,
        compRef: "gjxm",
        isSequenceFlag: true,
        isShowPage: true,
        resetFlag: true,
        loading: false,
        title: "灾情报送任务单列表",
        actions: [
          {
            id: "dialogVisible",
            text: "新增",
            type: "primary",
            btnAttr: { size: "small" }
          },
          // {
          //   id: "dialogVisible",
          //   text: "研判",
          //   type: "",
          //   btnAttr: { size: "small" }
          // }
          // {
          //   // id: "dialogVisible",
          //   text: "导出",
          //   type: "",
          //   btnAttr: { size: "small" }
          // }
          {
            id: "onExport",
            text: "导出",
            type: "",
            btnAttr: { size: "small" }
          }
        ],
        tableData: [],
        columns: [
          {
            prop: "emergencyEvent",
            label: "应急事件",
            align: "left",
            "min-width": "230px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      {...{
                        on: {
                          click: () => {
                            this.handleEmergencyEvents(row);
                          }
                        }
                      }}
                    >
                      {row.emergencyEvent}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "eventName",
            label: "事件类别",
            align: "center"
          },
          {
            prop: "eventLvName",
            label: "事件级别",
            align: "center"
          },
          {
            prop: "effectRange",
            label: "影响范围",
            align: "center"
          },
          {
            prop: "occurrenceTime",
            label: "发生时间",
            align: "center",
            "min-width": "150px"
          },
          {
            prop: "taskName",
            label: "任务名称",
            align: "left",
            "min-width": "200px"
            // render: (h, { row }) => {
            //   return (
            //     <div>
            //       {
            //         <span
            //           style='color:#3561fd;cursor:pointer;text-decoration: underline;'
            //           {...{
            //             on: {
            //               click: () => {
            //                 this.handleTaskName(row)
            //               }
            //             }
            //           }}
            //         >
            //           {row.taskName}
            //         </span>
            //       }
            //     </div>
            //   )
            // }
          },
          {
            prop: "reportTaskListVos",
            label: "任务内容及要求",
            align: "left",
            "min-width": "200px",
            "show-overflow-tooltip": false,
            render: (h, { row }) => {
              return (
                row.reportTaskListVos.map((item, index) => {
                  // console.log(item,"????item",index);
                  if (row.reportTaskListVos.length > 1 && index < row.reportTaskListVos.length - 1) {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.taskContent}</div>
                        <div style='border-bottom: 1px solid #EBEEF5;display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.taskContent}</div>
                      </el-tooltip>
                    );
                  } else {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.taskContent}</div>
                        <div style='display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.taskContent}</div>
                      </el-tooltip>
                    );
                  }

                })
              );
            }
          },
          {
            prop: "issueTime",
            label: "下发时间",
            align: "center",
            "show-overflow-tooltip": false,
            "min-width": "150px",
            render: (h, { row }) => {
              return (
                row.reportTaskListVos.map((item, index) => {
                  // console.log(item,"????item");
                  if (row.reportTaskListVos.length > 1 && index < row.reportTaskListVos.length - 1) {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.issueTime}</div>
                        <div style='border-bottom: 1px solid #EBEEF5;display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.issueTime}</div>
                      </el-tooltip>
                    );
                  } else {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.issueTime}</div>
                        <div style='#EBEEF5;display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.issueTime}</div>
                      </el-tooltip>
                    );
                  }
                  // return (
                  //   <tr>
                  //     <td>{item.issueTime}</td>
                  //   </tr>
                  // )
                })
              );
            }
          },
          {
            prop: "dutyDept",
            label: "报送单位/部门",
            align: "center",
            "show-overflow-tooltip": false,
            "min-width": "160px",
            render: (h, { row }) => {
              return (
                row.reportTaskListVos.map((item, index) => {
                  // console.log(item,"????item");
                  if (row.reportTaskListVos.length > 1 && index < row.reportTaskListVos.length - 1) {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.dutyDept}</div>
                        <div style='border-bottom: 1px solid #EBEEF5;display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.dutyDept}</div>
                      </el-tooltip>
                    );
                  } else {
                    return (
                      <el-tooltip effect='dark' placement='top'>
                        <div slot='content'>{item.dutyDept}</div>
                        <div style='display:-webkit-box;height:48px;line-height: 48px;align-items:center;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp: 2;'>{item.dutyDept}</div>
                      </el-tooltip>
                    );
                  }
                  // return (
                  //   <tr>
                  //     <td>{item.dutyDept}</td>
                  //   </tr>
                  // )
                })
              );
            }
          },
          {
            prop: "reportState",
            label: "状态",
            align: "center",
            "min-width": "100px",
            formatter: (row, column, cellValue, index) => {
              if (cellValue === "0") {
                return "编辑中";
              } else if (cellValue === "1") {
                return "待审核";
              } else if (cellValue === "2") {
                return "已下发";
              } else if (cellValue === "3") {
                return "驳回";
              }
            }
          },
          {
            prop: "cz",
            label: "操作",
            align: "center",
            fixed: "right",
            "min-width": "130px",
            render: (h, { row }) => {
              // console.log(row)
              return (
                <div>
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      // style: {display: row}
                      {...{
                        on: {
                          click: () => {
                            this.writeReport(row);
                          }
                        }
                      }}
                    >
                      {row.reportState === "0" && this.common.isHasPower("tbr") ? "编辑" : ""}
                    </span>
                  }
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;'
                      // style: {display: row}
                      {...{
                        on: {
                          click: () => {
                            this.writeReport(row);
                          }
                        }
                      }}
                    >
                      {row.reportState === "3" && this.common.isHasPower("tbr") ? "编辑" : ""}
                    </span>
                  }
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;text-decoration: underline;margin-left: 10px;'
                      {...{
                        on: {
                          click: () => {
                            this.writeReportDelete(row);
                          }
                        }
                      }}
                    >
                      删除
                    </span>
                  }
                </div>
              );
            }
          }
        ],
        tableAttr: {
          // "max-height": "470px",
          // height: "470px",
          stripe: false,
          border: true,
          fit: true,
          "show-header": true,
          "highlight-current-row": true,
          "cell-style": {
            "font-size": "16px"
          },
          "header-cell-style": {
            "text-align": "center",
            "background-color": "#B1C8F9",
            border: "1px solid #ccc",
            "font-size": "16px"
          }
        }
      },
      tableList: {
        isSelectFlag: true,
        compRef: "rwxx",
        isSequenceFlag: true,
        isShowPage: true,
        resetFlag: true,
        autoHeight: true,
        loading: false,
        title: "灾情报送任务单列表",
        actions: [
          {
            id: "dialogVisible",
            text: "新增",
            type: "primary",
            btnAttr: { size: "small" }
          }
          // {
          //   id: "dialogVisible",
          //   text: "研判",
          //   type: "",
          //   btnAttr: { size: "small" }
          // }
          // {
          //   // id: "dialogVisible",
          //   text: "导出",
          //   type: "",
          //   btnAttr: { size: "small" }
          // }
        ],
        tableData: [
          {
            taskContent: "",
            dutyDeptId: "",
            dutyDept: ""
          }
        ],
        columns: [
          {
            prop: "taskContent",
            label: "任务内容及要求",
            align: "center",
            "min-width": "200px",
            render: (h, { row }) => {
              return (
                <div class='peizhi'>
                  <LsdForm
                    compData={{
                      elType: "input",
                      id: "taskContent",
                      label: "任务内容及要求",
                      attrs: {
                        // disabled:
                        //   _this.operat === "review" ||
                        //   !["task999"].includes(_this.$route.query.task) ||
                        //   ["task2", "task3"].includes(
                        //     _this.$route.query.returnFlow
                        //   ),
                        disabled: false,
                        autosize: true,
                        value: "",
                        placeholder: "请输入",
                        min: 0,
                        type: "textarea"
                      }
                    }}
                    form={row}
                    {...{
                      on: {}
                    }}
                  ></LsdForm>
                </div>
              );
            }
          },
          {
            prop: "dutyDeptId",
            label: "报送单位/部门",
            align: "center",
            "width": "290px",
            tooltip: true,
            render: (h, { row }) => {
              return (
                <div class='peizhi'>
                  <LsdForm
                    compData={{
                      elType: "lsdTree",
                      id: "dutyDept",
                      name: "dutyDeptId",
                      treeRef: "treeBsdwRef",
                      keyWord: "keyWord",
                      commonClick: true,
                      label: " ",
                      isSplice: true,
                      // dic: "dic_zrbm",
                      attrs: {
                        value: "",
                        clearable: true,
                        "collapse-tags": true
                      },
                      options: {
                        attrs: {
                          value: ""
                        }
                      },
                      treeData: {
                        attrs: {
                          data: this.zrdwOption
                        },
                        props: {
                          children: "children",
                          label: "orgName",
                          value: "id"
                        }
                      }
                    }}
                    form={row}
                    {...{
                      on: {
                        "node-click": (data, item) => {
                          row.dutyDept = data.orgName;
                          row.dutyDeptId = data.id;
                        }
                      }
                    }}
                  ></LsdForm>
                </div>
              );
            }
          },
          {
            prop: "cz",
            label: "操作",
            align: "center",
            fixed: "right",
            "min-width": "40px",
            render: (h, { $index }) => {
              return (
                <div>
                  {
                    $index === this.tableList.tableData.length - 1 && (
                      <img
                        {...{
                          class: {},
                          style: {
                            width: "16px",
                            height: "16px",
                            "margin-right": "10px"
                          },
                          attrs: {
                            src: require("../../../assets/img/listAdd.png")
                          },
                          on: {
                            click: (scope) => {
                              this.$nextTick(() => {
                                this.tableList.tableData.push(
                                  {
                                    taskName: "",
                                    taskContent: "",
                                    dutyDeptId: "",
                                    dutyDept: ""
                                  }
                                );
                              });
                            }
                          }
                        }}
                      />
                    )
                  }
                  {this.tableList.tableData.length > 1 && (
                    <img
                      {...{
                        class: {},
                        style: {
                          width: "16px",
                          height: "16px",
                          cursor: "pointer"
                        },
                        attrs: {
                          src: require("../../../assets/img/listReduc.png")
                        },
                        on: {
                          click: () => {
                            this.tableList.tableData.splice($index, 1);
                          }
                        }
                      }}
                    />)}
                </div>
              );
            }
          }
        ],
        tableAttr: {
          // "min-height": "300px",
          // height: "500px",
          stripe: false,
          border: true,
          fit: true,
          "show-header": true,
          "highlight-current-row": true,
          "cell-style": {
            "font-size": "16px"
          },
          "header-cell-style": {
            "text-align": "center",
            "background-color": "#B1C8F9",
            border: "1px solid #ccc",
            "font-size": "16px"
          }
        }
      },
      paginationAtrrs: {
        total: 0,
        "background": true,
        layout: "prev, pager, next",
        "current-page": 1,
        "page-size": 10
      },
      activeNames: ["1", "2", "3", "4"],
      form: {},
      pageNum: 1,
      multipleSelection: [],
      // 弹窗信息
      dialogConfig: {
        title: "灾情报送任务单",
        isShow: false,
        btnList: [
          {
            name: "提交",
            id: "BSubmit", // 事件名
            type: "primary",
            size: "small"
          },
          {
            name: "保存",
            id: "BSave", // 事件名
            size: "small"
          },
          {
            name: "取消",
            id: "getBack", // 事件名
            size: "small"
          }
        ]
      },
      // 折叠面板信息
      titleConfig: [
        {
          title: "信息来源",
          name: "1",
          slot: "slot1"
        },
        {
          title: "任务信息",
          name: "2",
          slot: "slot2"
        },
        {
          title: "任务下发",
          name: "3",
          slot: "slot3"
        }
      ],
      formConfig: {
        formData: [
          {
            type: "select",
            label: "信息来源",
            prop: "yjtzd",
            class: "half",
            lableWidth: "100px"
          },
          {
            type: "select",
            label: "预警通知单",
            prop: "yjtszd",
            class: "half",
            lableWidth: "100px"
          }
        ],
        rules: {
          yjtzd: [
            { required: true, message: "请选择响应命令单", trigger: "blur" }
          ]
        }
      },
      formConfig1: {
        // disabled: true,
        formData: [
          {
            type: "select",
            label: "应急事件",
            prop: "emergencyEvent",
            class: "sjgy",
            lableWidth: "120px",
            option: []
          },
          {
            type: "select",
            label: "事件类别",
            prop: "eventCode",
            name: "eventName",
            class: "half",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "select",
            label: "事件级别",
            prop: "eventLvCode",
            name: "eventLvName",
            class: "half",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "影响范围",
            prop: "effectRange",
            class: "half",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "dataPicker",
            label: "发生时间",
            prop: "occurrenceTime",
            class: "half",
            dateType: "datetime",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "textarea",
            label: "事件概要",
            prop: "incidentOutline",
            class: "sjgy",
            isDisabled: true,
            lableWidth: "120px"
          }
          // {
          //   type: "upload",
          //   label: "附件",
          //   prop: "ztqks",
          //   lableWidth: "100px"
          // }
        ],
        rules: {
          emergencyEvent: [
            { required: true, message: "请选择应急事件", trigger: "blur" }
          ]
        }
      },
      formInfoData: {
        // disabled: true,
        formData: [
          // {
          //   type: "select",
          //   label: "应急事件",
          //   prop: "emergencyEvent",
          //   class: "sjgy",
          //   lableWidth: "100px",
          //   option: []
          // },
          {
            type: "input",
            label: "下发人",
            prop: "creator",
            class: "iputsse",
            isDisabled: true,
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "单位及部门",
            prop: "unitDeptName",
            isDisabled: true,
            class: "iputsse",
            lableWidth: "120px"
          },
          {
            type: "input",
            label: "下发时间",
            prop: "createTime",
            class: "iputsse",
            isDisabled: true,
            lableWidth: "120px"
          }
        ]

      },
      formConfig2: {
        formData: [
          {
            type: "input",
            label: "任务名称",
            prop: "taskName",
            class: "sjgy",
            lableWidth: "120px"
          }
        ],
        rules: {
          taskName: [
            { required: true, message: "请输入任务名称", trigger: "blur" }
          ]
        }
      },

      formCheckData: {
        formData: [
          {
            type: "input",
            label: "审批意见",
            isDisabled: true,
            prop: "emergencyEvent",
            class: "sjgy",
            lableWidth: "100px",
            option: []
          },
          {
            type: "readonly",
            label: "审批人",
            prop: "eventName",
            class: "iputsse",
            isDisabled: true,
            lableWidth: "100px"
          },
          {
            type: "readonly",
            label: "单位及部门",
            prop: "eventLvName",
            class: "iputsse",
            isDisabled: true,
            lableWidth: "100px"
          },
          {
            type: "readonly",
            label: "审批时间",
            prop: "effectRange",
            class: "iputsse",
            isDisabled: true,
            lableWidth: "100px"
          }

        ],
        rules: {
          ztqk: [
            { required: true, message: "请选择", trigger: "blur" }
          ]
        }
      },
      rules: {
        name: [
          { required: true, message: "请输入名称", trigger: "blur" }
        ]
      },
      options: {
        dic_sjlb: [],
        dic_sjjb: [],
        dic_yxfw: [],
        dic_xxly: [],
        dic_zrbm: []
      },
      editId: "", // 编辑id
      changeId: "",
      FilledBy: {}
    };
  },
  created() {
    this.list();
    this.getInputVal();
    this.getTasksOption();
    if (this.$route.query.id) {
      this.dialogVisible();
      this.GoGetAlertInformation();
    }
  },
  mounted() {
    const FilledBy = {
      creator: JSON.parse(sessionStorage.getItem("account")).realName,
      creatorId: JSON.parse(sessionStorage.getItem("account")).id,
      deptId: JSON.parse(sessionStorage.getItem("org")).orgCode,
      // unitDeptName: JSON.parse(sessionStorage.getItem("org")).orgName,
      unitDeptName: sessionStorage.getItem("dwbmName"),
      // createTime: new Date().toLocaleString(),
      createTime: showTime(new Date()),
      approvalUserId: JSON.parse(sessionStorage.getItem("account")).id,
      approvalUser: JSON.parse(sessionStorage.getItem("account")).realName,
      pprovalDeptId: JSON.parse(sessionStorage.getItem("org")).orgCode,
      approvalDept: JSON.parse(sessionStorage.getItem("org")).orgName,
      level: JSON.parse(sessionStorage.getItem("org")).level,
      approvalTime: new Date().toLocaleString()
    };
    this.FilledBy = FilledBy;
  },
  methods: {
    // 工作流提交
    gzlSubmit(bizKey, variable) {
      const data = {
        bizKey,
        flowKey: "emergency_report_001",
        taskId: "task1",
        callbackUrl: "/emergency/emergencyReport/handleFlow",
        idea: "1",
        variable
      };
      const successCallBack = () => {
        this.$message({
          message: "保存成功",
          type: "success"
        });
        this.$router.push({ query: {} });
        this.dialogConfig.isShow = false;
        this.list();
      };
      flowSubmit(data, successCallBack, "提交", true);
    },
    // 重置
    reset() {
      this.form = this.$options.data().form;
      this.pageNum = 1;
      this.$refs.gjxm.paginationAtrrsInner["current-page"] = 1;
      this.list();
    },
    // 查询
    async query() {
      var timeAndSecond1 = "";
      if (this.form.issueTime === undefined || this.form.issueTime === "") {
        this.form.issueTime = "";
      } else {
        timeAndSecond1 = this.form.issueTime[1].slice(0, 10) + " " + "23:59:59";
      }
      const parmas = {
        pageNum: this.pageNum,
        pageSize: 10,
        reportState: 0,
        dutyDeptId: this.form.operat, // 报送单位
        emergencyEvent: this.form.emergencyEvent, // 应急事件
        eventCode: this.form.eventCode, // 事件类别
        eventLvCode: this.form.eventLvName, // 事件级别
        occurrenceStartTime: this.form.occurrenceTime ? this.form.occurrenceTime[0] : "", // 发生开始时间
        occurrenceEndTime: this.form.occurrenceTime ? this.form.occurrenceTime[1] : "", // 发生结束时间
        taskName: this.form.taskName, // 任务名称
        createStateTime: this.form.issueTime ? this.form.issueTime[0] : "", // 下发开始时间
        // createEndTime: this.form.issueTime ? this.form.issueTime[1] : "" // 下发结束时间
        createEndTime: this.form.issueTime ? timeAndSecond1 : "" // 报送结束时间
        // issueTime: val.applyTime ? val.applyTime[0] : "", // 开始时间
        // taskPublishTimeEnd: val.applyTime ? val.applyTime[1] : "" // 结束时间
        // effectStartTime: this.form.effectStartTime ? this.form.effectStartTime[0] : "", // 开始时间
        // effectEndTime: this.form.effectStartTime ? this.form.effectStartTime[1] : "", // 结束时间
      };
      const res = await zqbsSubmissionList(parmas);
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    handleBtn(item) {
      this[item.id]();
    },
    resetForm() {
      this.tableConfig.formData = this.$options.data().tableConfig.formData;
      this.list();
    },
    // 列表筛选 组织机构
    handleSelectTree(arg, item) {
      if (item.id === "operatId") {
        this.$set(this.form, "operat", arg[0].id);
        this.$set(this.form, "operatId", arg[0].orgName);
      }
    },
    // 获取下拉框数据
    getInputVal() {
      this.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroupEmergency({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.options = option;
          });
        } else if (item.elType === "selectTree") {
          // GetOrgTree().then(res => {
          getOrgDepartmentList({ orgId: JSON.parse(sessionStorage.getItem("org")).orgId }).then(res => {
            this.$nextTick(() => {
              if (item.label === "报送单位/部门") {
                this.$set(this.formData[5].treeData.attrs, "data", res);
              }
            });
          });
        }
      });
      this.formConfig.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroupEmergency({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.option = option;
          });
        }
      });
      this.formConfig1.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroupEmergency({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.option = option;
          });
        }
      });
      getDictByGroupEmergency({ groupCode: "dic_zrbm" }).then(res => {
        console.log(res, ">>>>>>res");
        // const option = res.map((item) => {
        //   return {
        //     label: item.dicName,
        //     value: Number(item.dicCode)
        //   }
        // })
        // this.zrbmOption = option
        // console.log(this.zrbmOption, ">>>>>>>>zrbmOption")

        const option = res.map(item => {
          return {
            label: `${item.dicName}`,
            value: item.dicCode,
            ...item
          };
        });
        this.zrbmOption = option;
      });
    },
    getTasksOption() {
      const arr = [
        {
          dic: "dic_rwlx",
          option: "rwlxOption"
        },
        {
          dic: "dic_zy",
          option: "zylxOption"
        }
      ];
      arr.forEach(item => {
        getDictByGroup({ groupCode: item.dic }).then(res => {
          const option = res.map((item) => {
            return {
              label: item.dicName,
              value: item.dicCode
            };
          });
          this[item.option] = option;
        });
      });
      console.log(JSON.parse(sessionStorage.getItem("org")).level);
      // -----------
      if (JSON.parse(sessionStorage.getItem("org")).level == 1) {
        console.log("1111");
        getOrgListTree().then(res => {
          this.$set(this, "zrdwOption", res);
        });
      } else if (JSON.parse(sessionStorage.getItem("org")).level == 2) {
        console.log("22222");
        GetOrgTreeTwo({ id: JSON.parse(sessionStorage.getItem("org")).orgCode }).then(res => {
          this.$set(this, "zrdwOption", res);
        });
      } else {
        console.log("更多");
        GetOrgTreeMore({ id: JSON.parse(sessionStorage.getItem("org")).orgCode }).then(res => {
          this.$set(this, "zrdwOption", res);
        });
      }
      // GetOrgTree().then(res => {
      //   this.$set(this, "zrdwOption", res);
      // });
    },
    // 列表
    async list() {
      const parmas = {
        pageNum: this.pageNum,
        pageSize: 10,
        reportState: 0
      };
      const res = await zqbsSubmissionList(parmas);
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    onActionClick(item, index) {
      this[item.id](); // 调用按钮对应方法
    },
    // 新增
    dialogVisible() {
      this.xinzengNum = 0;
      this.dialogConfig.isShow = true;
      this.getTasksOption();
      // const userDep = JSON.parse(sessionStorage.getItem("org")).orgName
      // console.log(userDep)
      // console.log(this.$refs.formInfoData)
      // this.$set(this.$refs.formInfoData.form, "readonly", JSON.parse(sessionStorage.getItem("org")).orgName)
      this.$nextTick(() => {
        this.$refs.formInfoData.form = this.FilledBy;
      });
      this.formConfig1.formData.map(item => {
        if (item.label === "应急事件") {
          getYjsj().then(res => {
            const option = res.map((item) => {
              return {
                label: item.emergencyEvent,
                value: item.id
              };
            });
            item.option = option;

          });
        }
      });
    },
    // 导出操作
    onExport() {
      const parmas = {
        reportState: 0,
        emergencyEvent: this.form.emergencyEvent, // 应急事件
        eventCode: this.form.eventCode, // 事件类别
        eventLvCode: this.form.eventLvName, // 事件级别
        occurrenceTime: this.form.occurrenceTime, // 发生时间
        taskName: this.form.taskName, // 任务名称
        issueTime: this.form.issueTime // 下发时间
      };
      exportFileApi(parmas).then(res => {
        common.downloadByBlob(res, `灾情报送${new Date().getTime()}.xlsx`);
      });
    },
    // 应急事件 下拉监听
    handleChange(val) {
      console.log(val);
      getYjsjGetById({ id: val }).then(res => {
        console.log(res.id);
        this.changeId = res.id;
        this.$refs.formConfigData.form = res;
        console.log(this.$refs.formConfigData.form, "0000000");
        // this.$refs.formInfoData.form = res
      });
    },
    // 编辑
    writeReport(val) {
      console.log(val.id);
      this.editId = val.id;
      this.dialogVisible();
      this.getInputVal();
      if (val.reportState === "0" || val.reportState === "3") {
        this.dialogConfig.isShow = true;
        zqbsSubmissiongetById({ id: val.id }).then(res => {
          // console.log(res)
          this.$refs.formConfigData.form = res;
          this.$refs.formComponentData.form = res;
          this.$refs.formInfoData.form = res;
          // console.log(this.$refs.formInfoData.form, "lllllllppppp")
          this.$set(this.$refs.formInfoData.form, "unitDeptName", res.creatorDeptName);
          this.tableList.tableData = res.reportTaskListVos;
          // this.tableData = res.reportTaskListVos
          // formComponentData
        });
      }
      this.xinzengNum = 1;
    },
    // 应急灾情任务下发
    GoGetAlertInformation() {
      getYjsjGetById({ id: this.$route.query.id }).then(res => {
        console.log(res);
        this.$refs.formConfigData.form = res;
        this.$refs.formInfoData.form = res;
        this.$set(this.$refs.formInfoData.form, "unitDeptName", res.createDeptName);
      });
    },
    // 删除
    writeReportDelete(val) {
      console.log(val.id);
      // postDeleteData({ id: val.id }).then(res => {
      //   console.log(res);
      //   this.$message({
      //     message: "删除成功",
      //     type: "success"
      //   });
      //   // 刷新页面
      //   this.list();
      // });

      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        postDeleteData({ id: val.id }).then(data => {
          if (data) {
            this.$message({
              message: "删除成功",
              type: "success"
            });
            this.list();
          }
        });
      }).catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除"
        });
      });
    },
    // 多选单选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    selectChange(e, i) {
      console.log(e);
      console.log(i);
    },
    // 分页
    handleCurrentChange(val) {
      this.pageNum = val;
      this.list();
    },
    // 应急事件
    handleEmergencyEvents(val) {
      console.log(val);
      this.$router.push({
        path: "/EmergencyDetail",
        query: { id: val.emergencyId }

      });
    },
    // 详情
    handleTaskName(val) {
      // console.log(val)
      this.editId = val.id;
      this.dialogVisible();
      if (val.reportState === "0") {
        this.dialogConfig.isShow = true;
        zqbsSubmissiongetById({ id: val.id }).then(res => {
          // console.log(res)
          this.$refs.formConfigData.form = res;
          this.$refs.formComponentData.form = res;
          this.$refs.formInfoData.form = res;
          this.tableList.tableData = res.reportTaskListVos;
        });
      }

    },
    // 保存
    async BSave() {
      // console.log(this.$refs.formInfoData.form);
      console.log("保存");
      // 新增 保存
      this.$refs.formConfigData.isValidate();
      this.$refs.formComponentData.isValidate();
      const flag = this.$refs.formConfigData.flag;
      const flag1 = this.$refs.formComponentData.flag;
      let emptFlag = true;
      const newTableData = this.tableList.tableData;
      newTableData.forEach((item, index) => {
        if (item.taskContent === "" || item.taskContent === null || item.taskContent === undefined) {
          this.$message({
            message: `任务内容及要求列表，第${index + 1}条任务内容不能为空`,
            type: "error"
          });
          emptFlag = false;
        } else if (item.dutyDeptId === "" || item.dutyDeptId === null || item.dutyDeptId === undefined) {
          this.$message({
            message: `任务内容及要求列表，第${index + 1}条报送单位/部门不能为空`,
            type: "error"
          });
          emptFlag = false;
        }
      });
      if (flag && flag1 && emptFlag) {
        if (this.editId === "") {
          const parmas = {
            emergencyId: this.$refs.formConfigData.form.id,
            taskName: this.$refs.formComponentData.form.taskName,
            reportTaskSaveDto: this.tableList.tableData,
            creator: this.$refs.formInfoData.form.creator, // 创建人
            createId: this.$refs.formInfoData.form.creatorId, // 创建人id
            creatorDeptId: this.$refs.formInfoData.form.deptId, // 创建人部门id
            creatorDeptName: this.$refs.formInfoData.form.unitDeptName // 创建人部门名称
          };
          // console.log(parmas);
          const res = await addAave(parmas);
          if (res) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            this.$router.push({ query: {} });
            this.dialogConfig.isShow = false;
            this.list();
          }
        } else {
          // 编辑 保存
          const parmas = {
            id: this.editId,
            // emergencyId: this.$refs.formConfigData.form.emergencyId,
            emergencyId: this.changeId === "" ? this.$refs.formConfigData.form.emergencyId : this.changeId,
            taskName: this.$refs.formComponentData.form.taskName,
            reportTaskUpdDtos: this.tableList.tableData,
            creator: this.$refs.formInfoData.form.creator, // 创建人
            createId: this.$refs.formInfoData.form.creatorId, // 创建人id
            creatorDeptId: this.$refs.formInfoData.form.deptId, // 创建人部门id
            creatorDeptName: this.$refs.formInfoData.form.unitDeptName // 创建人部门名称
          };
          console.log(parmas);
          const res = await zqkcFeedbackUpdById(parmas);
          if (res) {
            this.$message({
              message: "修改成功",
              type: "success"
            });
            this.dialogConfig.isShow = false;
            this.list();
          }
        }
      }
    },
    // gzlSubmit
    async BSubmit() {
      console.log("提交");
      this.$refs.formConfigData.isValidate();
      this.$refs.formComponentData.isValidate();
      const flag = this.$refs.formConfigData.flag;
      const flag1 = this.$refs.formComponentData.flag;
      let emptFlag = true;
      const newTableData = this.tableList.tableData;
      newTableData.forEach((item, index) => {
        if (item.taskContent === "" || item.taskContent === null || item.taskContent === undefined) {
          this.$message({
            message: `任务内容及要求列表，第${index + 1}条任务内容不能为空`,
            type: "error"
          });
          emptFlag = false;
        } else if (item.dutyDeptId === "" || item.dutyDeptId === null || item.dutyDeptId === undefined) {
          this.$message({
            message: `任务内容及要求列表，第${index + 1}条报送单位/部门不能为空`,
            type: "error"
          });
          emptFlag = false;
        }
      });
      if (flag && flag1 && emptFlag) {
        if (this.editId === "") {
          const parmas = {
            emergencyId: this.$refs.formConfigData.form.id,
            taskName: this.$refs.formComponentData.form.taskName,
            reportTaskSaveDto: this.tableList.tableData,
            creator: this.$refs.formInfoData.form.creator, // 创建人
            createId: this.$refs.formInfoData.form.creatorId, // 创建人id
            creatorDeptId: this.$refs.formInfoData.form.deptId, // 创建人部门id
            creatorDeptName: this.$refs.formInfoData.form.unitDeptName // 创建人部门名称
          };
          // console.log(parmas);
          // const res = await postAddSubmission(parmas);
          const res = await addAave(parmas);
          if (res) {
            // this.$message({
            //   message: "提交成功",
            //   type: "success"
            // });
            this.gzlSubmit(res, parmas);
            // this.$router.push({ query: {} });
            // this.dialogConfig.isShow = false;
            // this.list();
          }
        } else {
          // 编辑 提交
          const parmas = {
            id: this.editId,
            // emergencyId: this.$refs.formConfigData.form.emergencyId,
            emergencyId: this.changeId === "" ? this.$refs.formConfigData.form.emergencyId : this.changeId,
            taskName: this.$refs.formComponentData.form.taskName,
            reportTaskUpdDtos: this.tableList.tableData,
            creator: this.$refs.formInfoData.form.creator, // 创建人
            createId: this.$refs.formInfoData.form.creatorId, // 创建人id
            creatorDeptId: this.$refs.formInfoData.form.deptId, // 创建人部门id
            creatorDeptName: this.$refs.formInfoData.form.unitDeptName // 创建人部门名称
          };
          console.log(parmas);
          // const res = await postAddSubmission(parmas);
          const res = await zqkcFeedbackUpdById(parmas);
          if (res) {
            this.gzlSubmit(this.editId, parmas);
            // this.$message({
            //   message: "提交成功",
            //   type: "success"
            // });
            // this.dialogConfig.isShow = false;
            // this.list();
          }
        }
      }
    },
    // 取消
    getBack() {
      this.editId = "";
      if (this.$route.query.type === 1) {
        // this.$router.push({
        //   name: "EmergencyList"
        // });
        this.$router.go(-1);
      }
      // this.$router.push({ query: {} })
      // this.close()
      // this.dialogConfig.isShow = false
      this.$router.push({ query: {} });
      this.$refs.formConfigData.form = this.$refs.formConfigData.$options.data().form;
      this.$refs.formComponentData.form = this.$refs.formComponentData.$options.data().form;
      this.$refs.formInfoData.form = this.$refs.formInfoData.$options.data().form;
      this.tableList.tableData = [{}];
      // this.$refs.formComponent3.form = this.$refs.formComponent3.$options.data().form
      // this.$refs.formComponent4.form = this.$refs.formComponent4.$options.data().form
      this.$nextTick(() => {
        this.$refs.formConfigData.$refs.formInlines.clearValidate();
        this.$refs.formComponentData.$refs.formInlines.clearValidate();
        this.$refs.formInfoData.$refs.formInlines.clearValidate();
        this.tableList.tableData = [{}];
        // this.$refs.formComponent3.$refs.formInlines.clearValidate()
        // this.$refs.formComponent4.$refs.formInlines.clearValidate()

      });
      this.dialogConfig.isShow = false;
    },
    close() {
      this.editId = "";
      if (this.$route.query.type === 1) {
        // this.$router.push({
        //   name: "EmergencyList"
        // });
        this.$router.go(-1);
      }
      this.$router.push({ query: {} });
      this.$refs.formConfigData.form = this.$refs.formConfigData.$options.data().form;
      this.$refs.formComponentData.form = this.$refs.formComponentData.$options.data().form;
      this.$refs.formInfoData.form = this.$refs.formInfoData.$options.data().form;
      this.tableList.tableData = [{}];
      // this.$refs.formComponent3.form = this.$refs.formComponent3.$options.data().form
      // this.$refs.formComponent4.form = this.$refs.formComponent4.$options.data().form
      this.$nextTick(() => {
        this.$refs.formConfigData.$refs.formInlines.clearValidate();
        this.$refs.formComponentData.$refs.formInlines.clearValidate();
        this.$refs.formInfoData.$refs.formInlines.clearValidate();
        this.tableList.tableData = [{}];
        // this.$refs.formComponent3.$refs.formInlines.clearValidate()
        // this.$refs.formComponent4.$refs.formInlines.clearValidate()

      });
      this.dialogConfig.isShow = false;
    },
    // 分页
    handleSizeChange(val) {
      this.pageNum = val["current-page"];
      this.pageSize = val["page-size"];
      this.list();
    }
  }
};
</script>

<style scoped lang="less">
// @import '../../../assets/style/ComponentStyle.less';
@import "../../../assets/style/common.less";
@import "../../../assets/style/ComponentStyle.less";
@import "../../../assets/style/pop-upNotification.less";

:deep(.el-breadcrumb__inner.is-link) {
  font-weight: 100;
  color: #fff;
}

.EmergencyList :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  color: #3270ff;
}

/deep/ .el-table tr {
  background: none !important;
}

.box {
  // width: 100%;
  // height: 80vh;
  // padding: 0;
  // margin: 0;
  margin-top: 20px;
  background-color: #fff;
  border-radius: 4px;
  padding: 10px;
  box-sizing: border-box;
}
</style>
